Don't print `Running` for commands that aren't run
authorAlex Crichton <alex@alexcrichton.com>
Thu, 11 Sep 2014 14:35:01 +0000 (07:35 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 11 Sep 2014 14:35:25 +0000 (07:35 -0700)
Also print the commands only right before they're actually run.

Closes #215

src/cargo/ops/cargo_rustc/job.rs
src/cargo/ops/cargo_rustc/job_queue.rs
src/cargo/ops/cargo_rustc/mod.rs
tests/test_cargo_bench.rs
tests/test_cargo_compile.rs
tests/test_cargo_cross_compile.rs
tests/test_cargo_profiles.rs
tests/test_cargo_test.rs

index fa11bb0954fd246e81a3ce45157d3496c49db454..6493772f1520fd549ea0ebd69caea49686e353ff 100644 (file)
@@ -1,14 +1,18 @@
+use std::io::IoResult;
+
+use core::MultiShell;
 use util::{CargoResult, Fresh, Dirty, Freshness};
 
-pub struct Job { dirty: Work, fresh: Work }
+pub struct Job { dirty: Work, fresh: Work, desc: String }
 
 pub type Work = proc():Send -> CargoResult<()>;
 
 impl Job {
     /// Create a new job representing a unit of work.
     pub fn new(dirty: proc():Send -> CargoResult<()>,
-               fresh: proc():Send -> CargoResult<()>) -> Job {
-        Job { dirty: dirty, fresh: fresh }
+               fresh: proc():Send -> CargoResult<()>,
+               desc: String) -> Job {
+        Job { dirty: dirty, fresh: fresh, desc: desc }
     }
 
     /// Consumes this job by running it, returning the result of the
@@ -19,4 +23,11 @@ impl Job {
             Dirty => (self.dirty)(),
         }
     }
+
+    pub fn describe(&self, shell: &mut MultiShell) -> IoResult<()> {
+        if self.desc.len() > 0 {
+            try!(shell.status("Running", self.desc.as_slice()));
+        }
+        Ok(())
+    }
 }
index bc5d2171871dc42c0c3b23581c5040832933b1cb..7c32426c75ee84ff3cb1c3bb98c7dc3ab9846fcc 100644 (file)
@@ -168,6 +168,9 @@ impl<'a, 'b> JobQueue<'a, 'b> {
             let fresh = job_freshness.combine(fresh);
             let my_tx = self.tx.clone();
             let id = id.clone();
+            if fresh == Dirty {
+                try!(config.shell().verbose(|shell| job.describe(shell)));
+            }
             self.pool.execute(proc() {
                 my_tx.send((id, stage, fresh, job.run(fresh)));
             });
index cc826349332a06c37563d0a4814b003dde8dbe90..dc917bdd1a6a17d1fbd05c0661659cbde71c1091 100644 (file)
@@ -109,10 +109,10 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package,
 
     // Prepare the fingerprint directory as the first step of building a package
     let (target1, target2) = fingerprint::prepare_init(cx, pkg, KindTarget);
-    let mut init = vec![(Job::new(target1, target2), Fresh)];
+    let mut init = vec![(Job::new(target1, target2, String::new()), Fresh)];
     if cx.config.target().is_some() {
         let (plugin1, plugin2) = fingerprint::prepare_init(cx, pkg, KindPlugin);
-        init.push((Job::new(plugin1, plugin2), Fresh));
+        init.push((Job::new(plugin1, plugin2, String::new()), Fresh));
     }
     jobs.enqueue(pkg, StageStart, init);
 
@@ -125,11 +125,17 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package,
     }
     let (freshness, dirty, fresh) =
         try!(fingerprint::prepare_build_cmd(cx, pkg));
+    let desc = match build_cmds.len() {
+        0 => String::new(),
+        1 => pkg.get_manifest().get_build()[0].to_string(),
+        _ => format!("custom build commands"),
+    };
     let dirty = proc() {
         for cmd in build_cmds.move_iter() { try!(cmd()) }
         dirty()
     };
-    jobs.enqueue(pkg, StageCustomBuild, vec![(Job::new(dirty, fresh), freshness)]);
+    jobs.enqueue(pkg, StageCustomBuild, vec![(Job::new(dirty, fresh, desc),
+                                              freshness)]);
 
     // After the custom command has run, execute rustc for all targets of our
     // package.
@@ -139,19 +145,20 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package,
     let (mut libs, mut bins) = (Vec::new(), Vec::new());
     for &target in targets.iter() {
         let work = if target.get_profile().is_doc() {
-            vec![(try!(rustdoc(pkg, target, cx)), KindTarget)]
+            let (rustdoc, desc) = try!(rustdoc(pkg, target, cx));
+            vec![(rustdoc, KindTarget, desc)]
         } else {
             let req = cx.get_requirement(pkg, target);
             try!(rustc(pkg, target, cx, req))
         };
 
         let dst = if target.is_lib() {&mut libs} else {&mut bins};
-        for (work, kind) in work.move_iter() {
+        for (work, kind, desc) in work.move_iter() {
             let (freshness, dirty, fresh) =
                 try!(fingerprint::prepare_target(cx, pkg, target, kind));
 
             let dirty = proc() { try!(work()); dirty() };
-            dst.push((Job::new(dirty, fresh), freshness));
+            dst.push((Job::new(dirty, fresh, desc), freshness));
         }
     }
     jobs.enqueue(pkg, StageLibraries, libs);
@@ -209,7 +216,7 @@ fn compile_custom(pkg: &Package, cmd: &str,
 
 fn rustc(package: &Package, target: &Target,
          cx: &mut Context, req: PlatformRequirement)
-         -> CargoResult<Vec<(Work, Kind)> >{
+         -> CargoResult<Vec<(Work, Kind, String)> >{
     let crate_types = target.rustc_crate_types();
     let root = package.get_root();
 
@@ -219,15 +226,9 @@ fn rustc(package: &Package, target: &Target,
     let primary = cx.primary;
     let rustcs = try!(prepare_rustc(package, target, crate_types, cx, req));
 
-    let _ = cx.config.shell().verbose(|shell| {
-        for &(ref rustc, _) in rustcs.iter() {
-            try!(shell.status("Running", rustc.to_string()));
-        }
-        Ok(())
-    });
-
     Ok(rustcs.move_iter().map(|(rustc, kind)| {
         let name = package.get_name().to_string();
+        let desc = rustc.to_string();
 
         (proc() {
             if primary {
@@ -243,7 +244,7 @@ fn rustc(package: &Package, target: &Target,
                 }))
             }
             Ok(())
-        }, kind)
+        }, kind, desc)
     }).collect())
 }
 
@@ -272,7 +273,7 @@ fn prepare_rustc(package: &Package, target: &Target, crate_types: Vec<&str>,
 
 
 fn rustdoc(package: &Package, target: &Target,
-           cx: &mut Context) -> CargoResult<Work> {
+           cx: &mut Context) -> CargoResult<(Work, String)> {
     let kind = KindTarget;
     let pkg_root = package.get_root();
     let cx_root = cx.layout(kind).proxy().dest().join("doc");
@@ -284,13 +285,10 @@ fn rustdoc(package: &Package, target: &Target,
 
     log!(5, "commands={}", rustdoc);
 
-    let _ = cx.config.shell().verbose(|shell| {
-        shell.status("Running", rustdoc.to_string())
-    });
-
     let primary = cx.primary;
     let name = package.get_name().to_string();
-    Ok(proc() {
+    let desc = rustdoc.to_string();
+    Ok((proc() {
         if primary {
             try!(rustdoc.exec().chain_error(|| {
                 human(format!("Could not document `{}`.", name))
@@ -309,7 +307,7 @@ fn rustdoc(package: &Package, target: &Target,
             }))
         }
         Ok(())
-    })
+    }, desc))
 }
 
 fn build_base_args(cx: &Context, mut cmd: ProcessBuilder,
index ed878ef28819f51e121fc273c697cd8b256fa372..bd171b94d3476a9cc4fe0f8c5c22b6c287a157eb 100644 (file)
@@ -61,8 +61,8 @@ test!(cargo_bench_verbose {
 
     assert_that(p.cargo_process("bench").arg("-v").arg("hello"),
         execs().with_stdout(format!("\
-{running} `rustc src[..]foo.rs [..]`
 {compiling} foo v0.5.0 ({url})
+{running} `rustc src[..]foo.rs [..]`
 {running} `[..]target[..]release[..]foo-[..] hello --bench`
 
 running 1 test
@@ -654,12 +654,12 @@ test!(bench_dylib {
     assert_that(p.cargo_process("bench").arg("-v"),
                 execs().with_status(0)
                        .with_stdout(format!("\
+{compiling} bar v0.0.1 ({dir})
 {running} [..]
+{compiling} foo v0.0.1 ({dir})
 {running} [..]
 {running} [..]
 {running} [..]
-{compiling} bar v0.0.1 ({dir})
-{compiling} foo v0.0.1 ({dir})
 {running} [..]target[..]release[..]bench-[..]
 
 running 1 test
@@ -681,10 +681,6 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
     assert_that(p.process(cargo_dir().join("cargo")).arg("bench").arg("-v"),
                 execs().with_status(0)
                        .with_stdout(format!("\
-{running} [..]
-{running} [..]
-{running} [..]
-{running} [..]
 {fresh} bar v0.0.1 ({dir})
 {fresh} foo v0.0.1 ({dir})
 {running} [..]target[..]release[..]bench-[..]
index 976dab4494f6b73019d7bce31797af09079016c1..af390469d79ac73c55e0666cbfabf84f9af87abb 100644 (file)
@@ -1158,6 +1158,7 @@ test!(verbose_build {
         .file("src/lib.rs", "");
     assert_that(p.cargo_process("build").arg("-v"),
                 execs().with_status(0).with_stdout(format!("\
+{compiling} test v0.0.0 ({url})
 {running} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib -g \
         -C metadata=[..] \
         -C extra-filename=-[..] \
@@ -1165,7 +1166,7 @@ test!(verbose_build {
         --dep-info [..] \
         -L {dir}{sep}target \
         -L {dir}{sep}target{sep}deps`
-{compiling} test v0.0.0 ({url})\n",
+",
 running = RUNNING, compiling = COMPILING, sep = path::SEP,
 dir = p.root().display(),
 url = p.url(),
@@ -1185,6 +1186,7 @@ test!(verbose_release_build {
         .file("src/lib.rs", "");
     assert_that(p.cargo_process("build").arg("-v").arg("--release"),
                 execs().with_status(0).with_stdout(format!("\
+{compiling} test v0.0.0 ({url})
 {running} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \
         --opt-level 3 \
         --cfg ndebug \
@@ -1194,7 +1196,7 @@ test!(verbose_release_build {
         --dep-info [..] \
         -L {dir}{sep}target{sep}release \
         -L {dir}{sep}target{sep}release{sep}deps`
-{compiling} test v0.0.0 ({url})\n",
+",
 running = RUNNING, compiling = COMPILING, sep = path::SEP,
 dir = p.root().display(),
 url = p.url(),
@@ -1229,6 +1231,7 @@ test!(verbose_release_build_deps {
         .file("foo/src/lib.rs", "");
     assert_that(p.cargo_process("build").arg("-v").arg("--release"),
                 execs().with_status(0).with_stdout(format!("\
+{compiling} foo v0.0.0 ({url})
 {running} `rustc {dir}{sep}foo{sep}src{sep}lib.rs --crate-name foo \
         --crate-type dylib --crate-type rlib \
         --opt-level 3 \
@@ -1239,6 +1242,7 @@ test!(verbose_release_build_deps {
         --dep-info [..] \
         -L {dir}{sep}target{sep}release{sep}deps \
         -L {dir}{sep}target{sep}release{sep}deps`
+{compiling} test v0.0.0 ({url})
 {running} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \
         --opt-level 3 \
         --cfg ndebug \
@@ -1251,8 +1255,7 @@ test!(verbose_release_build_deps {
         --extern foo={dir}{sep}target{sep}release{sep}deps/\
                      {prefix}foo-[..]{suffix} \
         --extern foo={dir}{sep}target{sep}release{sep}deps/libfoo-[..].rlib`
-{compiling} foo v0.0.0 ({url})
-{compiling} test v0.0.0 ({url})\n",
+",
                     running = RUNNING,
                     compiling = COMPILING,
                     dir = p.root().display(),
index 13c1c6663a414b19b3753c3413c0e8925c176d3f..1f06e35d0ba6f6c7088e72921795b11fec35dc74 100644 (file)
@@ -295,6 +295,7 @@ test!(linker_and_ar {
                                               .arg("-v"),
                 execs().with_status(101)
                        .with_stdout(format!("\
+{compiling} foo v0.5.0 ({url})
 {running} `rustc src/foo.rs --crate-name foo --crate-type bin -g \
     --out-dir {dir}{sep}target{sep}{target} \
     --dep-info [..] \
@@ -302,7 +303,6 @@ test!(linker_and_ar {
     -C ar=my-ar-tool -C linker=my-linker-tool \
     -L {dir}{sep}target{sep}{target} \
     -L {dir}{sep}target{sep}{target}{sep}deps`
-{compiling} foo v0.5.0 ({url})
 ",
                             running = RUNNING,
                             compiling = COMPILING,
index e51ad49c78f941454255f984dfc853d9143b5424..c85b43db064d4425c289050c69ed719eb1527567 100644 (file)
@@ -25,6 +25,7 @@ test!(profile_overrides {
         .file("src/lib.rs", "");
     assert_that(p.cargo_process("build").arg("-v"),
                 execs().with_status(0).with_stdout(format!("\
+{compiling} test v0.0.0 ({url})
 {running} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \
         --opt-level 1 \
         --cfg ndebug \
@@ -34,7 +35,7 @@ test!(profile_overrides {
         --dep-info [..] \
         -L {dir}{sep}target \
         -L {dir}{sep}target{sep}deps`
-{compiling} test v0.0.0 ({url})\n",
+",
 running = RUNNING, compiling = COMPILING, sep = path::SEP,
 dir = p.root().display(),
 url = p.url(),
@@ -77,6 +78,7 @@ test!(top_level_overrides_deps {
         .file("foo/src/lib.rs", "");
     assert_that(p.cargo_process("build").arg("-v").arg("--release"),
                 execs().with_status(0).with_stdout(format!("\
+{compiling} foo v0.0.0 ({url})
 {running} `rustc {dir}{sep}foo{sep}src{sep}lib.rs --crate-name foo \
         --crate-type dylib --crate-type rlib \
         --opt-level 1 \
@@ -87,6 +89,7 @@ test!(top_level_overrides_deps {
         --dep-info [..] \
         -L {dir}{sep}target{sep}release{sep}deps \
         -L {dir}{sep}target{sep}release{sep}deps`
+{compiling} test v0.0.0 ({url})
 {running} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \
         --opt-level 1 \
         -g \
@@ -99,8 +102,7 @@ test!(top_level_overrides_deps {
         --extern foo={dir}{sep}target{sep}release{sep}deps/\
                      {prefix}foo-[..]{suffix} \
         --extern foo={dir}{sep}target{sep}release{sep}deps/libfoo-[..].rlib`
-{compiling} foo v0.0.0 ({url})
-{compiling} test v0.0.0 ({url})\n",
+",
                     running = RUNNING,
                     compiling = COMPILING,
                     dir = p.root().display(),
index a7685e08547524c3604c16d7b5007fcfbd57ae90..0b29040cc99d094b65da7a8f42dc4cfa81802355 100644 (file)
@@ -58,8 +58,8 @@ test!(cargo_test_verbose {
 
     assert_that(p.cargo_process("test").arg("-v").arg("hello"),
         execs().with_stdout(format!("\
-{running} `rustc src[..]foo.rs [..]`
 {compiling} foo v0.5.0 ({url})
+{running} `rustc src[..]foo.rs [..]`
 {running} `[..]target[..]foo-[..] hello`
 
 running 1 test